﻿using System;
using System.Net;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ScarecrowLibrary;

namespace ScarecrowLibrary.Network
{
    /// <summary>
    /// Contiene le informazioni sul profilo di rete
    /// </summary>
    [Serializable]
    public class scAdapterProfile
    {
        #region Properties
        public bool Enabled
        {
            get;
            set;
        }
        public string NetworkAdapter
        {
            get;
            set;
        }
        public bool IsIPDhcp
        {
            get;
            set;
        }
        public string IPAddress
        {
            get;
            set;
        }
        public string SubnetMask
        {
            get;
            set;
        }
        public string Gateway
        {
            get;
            set;
        }
        public bool IsDNSDhcp
        {
            get;
            set;
        }
        public string DNS1
        {
            get;
            set;
        }
        public string DNS2
        {
            get;
            set;
        }
        #endregion

        #region Fields
        #endregion

        #region Methods
        public scAdapterProfile()
        {
            this.Enabled = true;
            this.NetworkAdapter = this.IPAddress = this.SubnetMask = this.Gateway = this.DNS1 = this.DNS2 = "";
            this.IsDNSDhcp = this.IsIPDhcp = true;
        }
        #endregion

        #region Ovverride
        public override int GetHashCode()
        {
            string s = this.NetworkAdapter + this.Enabled;

            if (this.Enabled)
            {
                s += this.IsIPDhcp.ToString() + this.IsDNSDhcp.ToString();
                if (!this.IsIPDhcp)
                {
                    s += this.IPAddress + this.SubnetMask + this.Gateway;
                }
                if (!this.IsDNSDhcp)
                {
                    s += this.DNS1 + this.DNS2;
                }
            }
            return s.GetHashCode();
        }
        public override bool Equals(object obj)
        {
            return Equals(obj as scAdapterProfile);
        }
        public bool Equals(scAdapterProfile na)
        {
            if ((object)na == null)
                return false;

            return this.GetHashCode() == na.GetHashCode();
        }
        public static bool operator ==(scAdapterProfile ap1, scAdapterProfile ap2)
        {
            if (object.ReferenceEquals(ap1, ap2))
                return true;

            if ((object)ap1 == null || (object)ap2 == null)
                return false;

            return ap1.GetHashCode() == ap2.GetHashCode();
        }
        public static bool operator !=(scAdapterProfile ap1, scAdapterProfile ap2)
        {
            return !(ap1 == ap2);
        }
        #endregion
    }
}
